package com.petlab.dao.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import com.petlab.dao.RoleAuthorityDao;
import com.petlab.model.RoleAuthority;

@Component("roleAuthorityDao")
public class RoleAuthorityDaoImpl implements RoleAuthorityDao {

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}

	public void saveRoleAuth(RoleAuthority roleAuthority) {
		// TODO Auto-generated method stub
		hibernateTemplate.save(roleAuthority);
	}
	public ArrayList<RoleAuthority> getRoleByRolename(String rolename) {
		// TODO Auto-generated method stub
		ArrayList<RoleAuthority> roles = new ArrayList<RoleAuthority>();
		List<?> list = hibernateTemplate.find("from RoleAuthority u where u.roleAuthorityPK.rolename = '" + rolename + "'");
		if(null!=list&&list.size()>0)
		{
			for(int i=0;i<list.size();i++)
			{
				RoleAuthority roleAuthority = (RoleAuthority)list.get(i);
				
				roles.add(roleAuthority);
			}
		}
		return roles;
	}
}
